package com.wechat.back.service.impl;

import com.wechat.back.mapper.LikeMapper;
import com.wechat.back.pojo.comment.ArticleLike;
import com.wechat.back.pojo.comment.PoiLike;
import com.wechat.back.service.LikeService;
import com.wechat.back.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class LikeServiceImpl implements LikeService {
    @Autowired
    private LikeMapper likeMapper;
    @Override
    public void addArticleLike(ArticleLike articleLike) {
        articleLike.setCreateTime(LocalDateTime.now());
        likeMapper.addArticleLike(articleLike);
    }
    @Override
    public void addPoiLike(PoiLike poiLike) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        poiLike.setUserId(userId);
        poiLike.setCreateTime(LocalDateTime.now());
        likeMapper.addPoiLike(poiLike);
    }
    @Override
    public List<ArticleLike> listArticleLike(ArticleLike articleLike) {
        return likeMapper.listArticleLike(articleLike);
    }
    @Override
    public List<PoiLike> listPoiLike(Integer poiId) {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer userId = (Integer) map.get("id");
        return likeMapper.listPoiLike(poiId,userId);
    }
    @Override
    public void deleteArticleLike(Integer likeId) {
        likeMapper.deleteArticleLike(likeId);
    }
    @Override
    public void deletePoiLike(Integer likeId) {
        likeMapper.deletePoiLike(likeId);
    }
}
